package com.qipay.baas.mapper;

import com.qipay.baas.model.Message;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface MessageMapper {
    @Delete({
        "delete from message",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into message (send_by, send_name, ",
        "receive_by, receive_name, ",
        "content, `status`, ",
        "`type`, create_time)",
        "values (#{sendBy,jdbcType=INTEGER}, #{sendName,jdbcType=VARCHAR}, ",
        "#{receiveBy,jdbcType=INTEGER}, #{receiveName,jdbcType=VARCHAR}, ",
        "#{content,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}, ",
        "#{type,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(Message record);

    @InsertProvider(type=MessageSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insertSelective(Message record);

    @Select({
        "select",
        "id, send_by, send_name, receive_by, receive_name, content, `status`, `type`, ",
        "create_time",
        "from message",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="send_by", property="sendBy", jdbcType=JdbcType.INTEGER),
        @Result(column="send_name", property="sendName", jdbcType=JdbcType.VARCHAR),
        @Result(column="receive_by", property="receiveBy", jdbcType=JdbcType.INTEGER),
        @Result(column="receive_name", property="receiveName", jdbcType=JdbcType.VARCHAR),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.TINYINT),
        @Result(column="type", property="type", jdbcType=JdbcType.TINYINT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP)
    })
    Message selectByPrimaryKey(Integer id);

    @UpdateProvider(type=MessageSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Message record);

    @Update({
        "update message",
        "set send_by = #{sendBy,jdbcType=INTEGER},",
          "send_name = #{sendName,jdbcType=VARCHAR},",
          "receive_by = #{receiveBy,jdbcType=INTEGER},",
          "receive_name = #{receiveName,jdbcType=VARCHAR},",
          "content = #{content,jdbcType=VARCHAR},",
          "`status` = #{status,jdbcType=TINYINT},",
          "`type` = #{type,jdbcType=TINYINT},",
          "create_time = #{createTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Message record);
}